import java.io.*;
import java.util.*;

//Prueba de que el script se puede ejecutar desde java.
//Prueba superada!

//El problema es con el scp: no crea el fichero o pregunta antes por el password.

public class prova{

  public static void main(String args[]) throws Exception{
      
      String id = "P";
      String s = null;

      List<String> command = new ArrayList<String>();
      command.add("sh");
      command.add("pmainframe.sh");
      command.add(id);                            //idExperiment
      //Desde el directorio local funciona!
      //command.add("randset.10");     //inFile
      command.add("/home/worker/65.dat");
      command.add(".");                           //outputDir
      command.add("11");

      ProcessBuilder builder = new ProcessBuilder(command);
      // Redirects stderror to stdout
      builder.redirectErrorStream(true);
      Process process = builder.start();

      // Redirigimos la salida estándar:
      BufferedReader stdInput = new BufferedReader(new 
                 InputStreamReader(process.getInputStream()));
      BufferedReader stdError = new BufferedReader(new 
                 InputStreamReader(process.getErrorStream()));
      System.out.println("Here is the standard output of the command:\n");
      while ((s = stdInput.readLine()) != null) {
        System.out.println(s);
      }
      System.out.println("Here is the standard error of the command (if any):\n");
      while ((s = stdError.readLine()) != null) {
        System.out.println(s);
      }
      int exit = process.waitFor(); //Nos esperamos a que acabe.

    }

}